<div class="widget-box widget-color-blue">
	<div class="widget-header">
		<h5 class="widget-title">溯码后台配置</h5>

		<div class="widget-toolbar">
			<a href="#" data-action="collapse">
				<i class="1 ace-icon fa fa-chevron-up bigger-125"></i>
			</a>
		</div>

		<div class="widget-toolbar no-border">
			<button class="btn btn-xs btn-primary" onclick="ShowPageWxmpConfigList()">
				<i class="ace-icon fa fa-arrow-left"></i>
				返回
			</button>
		</div>
	</div>

	<div class="widget-body">

		<div class="widget-main">
			<div class="row">
				<div class="col-sm-12 widget-container-col" id="widget-container-col-12">
					<div class="widget-box transparent" id="widget-box-12">
						<div class="widget-header">
							<h4 class="widget-title">配置信息</h4>
							<div class="widget-toolbar">
								<a href="#" data-action="collapse">
									<i class="1 ace-icon fa fa-chevron-up bigger-125"></i>
								</a>
							</div>
						</div>

						<div class="widget-body">
							<div class="widget-main padding-6 no-padding-left no-padding-right">
								<div class="profile-user-info profile-user-info-striped">

									{% for field in field_info.fields %}
										<div class="profile-info-row">
											<div class="profile-info-name" style="width: 150px">{{ field.label }}</div>
											<div class="profile-info-value">
												{% if field.name == "value" %}
													{#	<img class="editable" id="{{ field.name }}" style="height: 96px;" src="{{ field.value }}" onclick="showBoxImage(this)">#}
													{% if field_info.input_type == "file" %}
														<input type="file" id="kv-explorer" name="file" value="{{ field.value|safe }}">
													{% else %}
														<span class="editable" id="{{ field.name|safe }}">{{ field.value|safe }}</span>
													{% endif %}
												{% elif field.name == "id" %}
													<span class="editable" id="param_id" p_value="{{ field.value|safe }}">{{ field.value|safe }}</span>
												{% else %}
													<span class="editable" id="{{ field.name|safe }}">{{ field.value|safe }}</span>
												{% endif %}
											</div>
										</div>
									{% endfor %}
								</div>
							</div>
						</div>
					</div>
				</div>


				<div class="col-xs-12 col-sm-9">

				</div>
			</div>
		</div>

		<div class="widget-toolbox padding-8 clearfix">
			<button class="btn btn-xs btn-success pull-left" onclick="ShowPageWxmpConfigList()">
				<i class="ace-icon fa fa-arrow-left"></i>
				<span class="bigger-110">返回</span>
			</button>
		</div>
	</div>

</div>
<script>
	init_file_input();

	function init_file_input() {
		var inputObj = $("#kv-explorer");
		if (inputObj == null || inputObj == undefined) {
			return;
		}

		var preValue = '{{ field_info.value_data|safe }}';
		var a_fileInput = $("#kv-explorer").fileinput({
			language: 'zh',
			uploadUrl: '/smAdmin/FileUpload',

			allowedFileExtensions: ['jpg', 'png', 'gif', 'jpeg'],
			allowedFileTypes: ['image'],
			allowedPreviewTypes: ['image'],

			overwriteInitial: false,
			maxFileSize: 1000,
			maxFilesNum: 1,
			initialPreviewCount: 1,

			showRemove: false,
			showPreview: true,
			initialPreviewAsData: true,
			initialPreview: [
				preValue,
			],

			initialPreviewConfig: [
				{
					caption: "xxx.jpg",
					size: 10,
					width: "120px",
					extra: {id: 100},
					key: 1
				}
			],

			slugCallback: function (filename) {
				return filename.replace('(', '_').replace(']', '_');
			}
		});

		a_fileInput.on("fileuploaded", function (e, data) {
			var res = data.response;
			if (res.result == 0) {
				setParamValue(res.img_url);
			} else {
				alert(res.reason);
			}
		});
		
		function setParamValue(value) {
			var id = $("#param_id").attr('p_value');

			function callback(data, status, xhr) {
				if (status == "success") {
					alert(data.reason);
				} else {
					alert("错误信息: <br/>" + xhr.status + "，" + xhr.statusText)
				}
			}

			var p_data = {"id": id, "value": value};
			$.post('/smAdmin/sysconf/smadmin_config_set_value', p_data, callback, "json")
		}
	}

</script>
